<?php

namespace app\api\model\job;

use app\common\model\job\Job as Model;

class Job extends Model
{
    public function getAllList($param = [])
    {
        $query = $this->getNewQuery();
        // 查询参数
        $filter = $this->getQueryFilter($param);
        // 查询列表记录
        $list = $query
            ->where($filter)
            ->where('is_delete', '=', '0')
            ->order(['subject_id' => 'desc'])
            ->select();

        return $list;
    }

    public function getQueryFilter($param)
    {
        $params = $this->setQueryDefaultValue($param, [
            'subject_name' => '',
        ]);

        $filter = [
            ["status", "=", 0],
        ];
        !empty($params['subject_name']) && $filter[] = ["subject_name", "like", "%{$params['subject_name']}%"];
        if (!empty($params['create_time'])) {
            $times = between_time($params['create_time']);
            $filter[] = ['create_time', '>=', $times['start_time']];
            $filter[] = ['create_time', '<', $times['end_time'] + 86400];
        }
        return $filter;
    }
}
